<?php

use Phalcon\Mvc\Model;

class Comments extends Model {

    protected $id;
    protected $text;
    protected $from;
    protected $to;
    protected $comment;
    protected $visible;
    protected $origin;
    protected $create_date;
    protected $update_date;

    public function initialize() {
        $this->belongsTo("from", "Users", "id");
        $this->belongsTo("to", "Users", "id");
        $this->belongsTo("text", "Texts", "id");
    }

    public function getSource() {
		return "lb_comment";
	}



    /**
     * Get the value of Id
     *
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set the value of Id
     *
     * @param mixed id
     *
     * @return self
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }

    /**
     * Get the value of Text
     *
     * @return mixed
     */
    public function getText()
    {
        return $this->text;
    }

    /**
     * Set the value of Text
     *
     * @param mixed text
     *
     * @return self
     */
    public function setText($text)
    {
        $this->text = $text;

        return $this;
    }

    /**
     * Get the value of From
     *
     * @return mixed
     */
    public function getFrom()
    {
        return $this->from;
    }

    /**
     * Set the value of From
     *
     * @param mixed from
     *
     * @return self
     */
    public function setFrom($from)
    {
        $this->from = $from;

        return $this;
    }

    /**
     * Get the value of To
     *
     * @return mixed
     */
    public function getTo()
    {
        return $this->to;
    }

    /**
     * Set the value of To
     *
     * @param mixed to
     *
     * @return self
     */
    public function setTo($to)
    {
        $this->to = $to;

        return $this;
    }

    /**
     * Get the value of Comment
     *
     * @return mixed
     */
    public function getComment()
    {
        return $this->comment;
    }

    /**
     * Set the value of Comment
     *
     * @param mixed comment
     *
     * @return self
     */
    public function setComment($comment)
    {
        $this->comment = $comment;

        return $this;
    }

    /**
     * Get the value of Create Date
     *
     * @return mixed
     */
    public function getCreateDate()
    {
        return $this->create_date;
    }

    /**
     * Set the value of Create Date
     *
     * @param mixed create_date
     *
     * @return self
     */
    public function setCreateDate($create_date)
    {
        $this->create_date = $create_date;

        return $this;
    }

    /**
     * Get the value of Update Date
     *
     * @return mixed
     */
    public function getUpdateDate()
    {
        return $this->update_date;
    }

    /**
     * Set the value of Update Date
     *
     * @param mixed update_date
     *
     * @return self
     */
    public function setUpdateDate($update_date)
    {
        $this->update_date = $update_date;

        return $this;
    }

    public function convertToArray() {
        $result = array(
            "id"    => (int)$this->id,
            "from"  => Users::findFirst($this->from)->convertToArray(),
            "visible" => (int)$this->visible,
            "comment"=> $this->comment,
            "text"  => $this->texts
        );
        if($this->origin == 1) {
            $result['to'] = null;
        }else {
            $result['to'] = Users::findFirst($this->to)->convertToArray();
        }

        return $result;
    }


    /**
     * Get the value of Origin
     *
     * @return mixed
     */
    public function getOrigin()
    {
        return $this->origin;
    }

    /**
     * Set the value of Origin
     *
     * @param mixed origin
     *
     * @return self
     */
    public function setOrigin($origin)
    {
        $this->origin = $origin;

        return $this;
    }


    /**
     * Get the value of Visible
     *
     * @return mixed
     */
    public function getVisible()
    {
        return $this->visible;
    }

    /**
     * Set the value of Visible
     *
     * @param mixed visible
     *
     * @return self
     */
    public function setVisible($visible)
    {
        $this->visible = $visible;

        return $this;
    }

}
